<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="小区" prop="areaName">
        <el-select v-model="queryParams.areaName":filter-method="filterMethod" placeholder="请输入小区" filterable allow-create
                   clearable size="small" @change="getGroup(queryParams.areaName)" default-first-option>
          <el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.areaName"
                     :value="item.areaName" :disabled="item.disabled" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="楼宇" prop="groupName">
        <el-select v-model="queryParams.groupName" placeholder="请输入楼宇" clearable :style="{width: '100%'}" @change="getUnit(queryParams.areaName,queryParams.groupName)">
          <el-option v-for="(item, index) in groupIdOptions" :key="index" :label="item.groupName"
                     :value="item.groupName" :disabled="item.disabled" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="单元" prop="unitName">
        <el-select v-model="queryParams.unitName" placeholder="请输入楼宇" clearable :style="{width: '100%'}" >
          <el-option v-for="(item, index) in unitNameOptions" :key="index" :label="item.unitName"
                     :value="item.unitName" :disabled="item.disabled" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="户" prop="doorName">
        <el-input
          v-model="queryParams.doorName"
          placeholder="请输入户名称"
          clearable
          :style="{width: '100%'}"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房屋编号" prop="houseId">
        <el-input
          v-model="queryParams.houseId"
          placeholder="请输入房屋编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="缴费时间" prop="costDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.costDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择缴费时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="缴费渠道" prop="costWay">
        <el-select v-model="queryParams.costWay" placeholder="请选择缴费渠道" clearable size="small">
          <el-option
            v-for="dict in dict.type.COST002"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="对账状态" prop="checkSts">
        <el-select v-model="queryParams.checkSts" placeholder="请选择对账状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.COST003"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发票号码" prop="billNo">
        <el-input
          v-model="queryParams.billNo"
          placeholder="请输入发票号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     <el-col :span="1.5">
       <el-button
         type="danger"
         plain
         icon="el-icon-delete"
         :disabled="multiple"
         size="mini"
         @click="handleDelete"
       >退款</el-button>
       </el-col>
    </el-row>

    <el-dialog :title="titleRefundExecute" :visible.sync="openRefundExecute" append-to-body width="500px">
      <el-form ref="form" :model="formRefundExecute" :rules="rules" label-width="80px">
        <el-form-item label="退款时间" prop="refundDate">
          <el-date-picker v-model="formRefundExecute.refundDate"
                          :style="{width: '100%'}"
                          clearable
                          placeholder="选择执行时间"
                          type="date" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRefundExecuteForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-table v-loading="loading" :data="refundList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="小区" align="center" prop="areaName" />
      <el-table-column label="楼宇" align="center" prop="groupName" />
      <el-table-column label="单元" align="center" prop="unitName" />
      <el-table-column label="户" align="center" prop="doorName" />
      <el-table-column label="房屋编号" align="center" prop="houseId" />
      <el-table-column label="流水号" align="center" prop="serial" />
      <el-table-column label="缴费金额" align="center" prop="costMoney" />
      <el-table-column label="缴费时间" align="center" prop="costDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.costDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="缴费状态" align="center" prop="costSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.COST001" :value="scope.row.costSts"/>
        </template>
      </el-table-column>
      <el-table-column label="缴费渠道" align="center" prop="costWay">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.COST002" :value="scope.row.costWay"/>
        </template>
      </el-table-column>
      <el-table-column label="对账状态" align="center" prop="checkSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.COST003" :value="scope.row.checkSts"/>
        </template>
      </el-table-column>
      <el-table-column label="退款状态" align="center" prop="refundSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.COST005" :value="scope.row.refundSts"/>
        </template>
      </el-table-column>
      <el-table-column label="发票号码" align="center" prop="billNo" />
      <el-table-column label="收费员" align="center" prop="creater" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRefund, getRefund, delRefund, getAreaInfo1,getAreaInfo, getGroupInfo, getUnitInfo } from "@/api/fund/refund";
import {getNote} from "../../../api/fund/refund";
import {executeProject} from "@/api/repair/project";

export default {
  name: "Refund",
  dicts: ['COST003', 'COST002', 'COST001', 'COST005'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 缴费信息表格数据
      refundList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openRefundExecute: false,
      // 弹出层标题
      titleRefundExecute: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaName: null,
        groupName: null,
        unitName: null,
        doorName: null,
        houseId: null,
        costDate: null,
        costSts: null,
        costWay: null,
        checkSts: null,
        billNo: null,
      },
      areaIdOptions:[{}],
      groupIdOptions:[{}],
      unitNameOptions:[{}],
      purposeOptions:[{}],
      // 表单参数
      form: {},
      formRefundExecute: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.filterMethod();
  },
  methods: {
    filterMethod(val){
      this.value=val
      getAreaInfo1(this.value).then(response => {
        this.areaIdOptions = response.rows;
      });
    },
    areaSelect(){
      getAreaInfo().then(response => {
        this.areaIdOptions = response.rows;
      });
    },
    getGroup(areaName){
      if(areaName!=""){
        getGroupInfo(areaName).then(response => {
          this.groupIdOptions = response.rows;
        });
      }
    },
    getUnit(areaName,groupName){
      getUnitInfo(areaName,groupName).then(response => {
        this.unitNameOptions = response.rows;
      });
    },
    /** 查询缴费信息列表 */
    getList() {
      this.loading = true;
      listRefund(this.queryParams).then(response => {
        this.refundList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openRefundExecute = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        costId: null,
        houseId: null,
        serial: null,
        costMoney: null,
        costDate: null,
        costSts: null,
        costWay: null,
        checkSts: null,
        billNo: null,
        creater: null,
        createDate: null,
        refundDate:null,
        areaName:null,
        groupName:null,
        unitName:null,
        doorName:null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.areaSelect();
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.multiple = !selection.length;
            selection.map(item => {
            })
      this.ids = selection.map(item => item.costId)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.reset();
      this.openRefundExecute = true;
      this.titleRefundExecute = "退款时间";
    },

    /** 执行按钮操作 */
    submitRefundExecuteForm() {
      debugger
      delRefund(this.ids, this.formRefundExecute.refundDate).then(response => {
        this.$modal.msgSuccess("退款成功");
        this.openRefundExecute = false;
        this.getList();
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('fund/refund/export', {
        ...this.queryParams
      }, `refund_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
